#pragma once
#include<iostream>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string>
#include <fcntl.h>

using namespace std;
const string PipeFile="./PipeFile";
const mode_t pri=0600;
const int defaultfd=-1;
const int Size=1024;
class Fifo{
    public:
Fifo()

 :_fd(-1)
{
     umask(0);
    int n=mkfifo(PipeFile.c_str(),pri);
    if(n<0)
    {
        cerr<<"mkfifo Error"<<endl;
        return;
    }
}
 bool OpenPipeForWrite()
    {
        _fd = open(PipeFile.c_str(), O_WRONLY);
        if (_fd < 0)
        {
            cerr << " Client open Error" << endl;
            return false;
        }
        return true;
    }
  bool OpenPipeForRead()
    {
        cout<<"1"<<endl;
        _fd = open(PipeFile.c_str(), O_RDONLY);
        cout<<"2"<<endl;
        if (_fd < 0)
        {
            cerr << " Client open Error" << endl;
            return false;
        }
        return true;
    }
    void Write(){
        int n=1;
        write(_fd,&n,sizeof n);
    }
    void Read(){
        int n=0;
        read(_fd,&n,sizeof n);
    }
~Fifo(){ int n=unlink(PipeFile.c_str());
       if(n<0)
    {
        cerr<<"unlink Error"<<endl;
        return;
    }
    cout<<"unlink success"<<endl;}
private:
int _fd;
};
Fifo ff2;
//Fifo ff2;